//
//  EvaluateViewController.m
//  EducationAdminClient
//
//  Created by xuyingwei on 16/11/8.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "EvaluateViewController.h"
#import "EvaluateTableViewCell.h"
#import "ListVCCellTwo.h"
#import "AddViewController.h"
#import "ListDetailViewController.h"
#import "MJRefresh.h"


#import "SearchViewController.h"


#import "SelectRelationViewController.h"

#import "WBPopMenuModel.h"
#import "WBPopMenuSingleton.h"
#define kRadianToDegrees(radian) (radian*180.0)/(M_PI)
#define TABLEVIEWHEADERHEIGHT 86/2

#define SHOULDRELOAD @"shouldReload"
#define TopSelectViewHeight 40
#define TopSelectBtnBottomLineColor 0x5da6ff
#define TopSelectBtnBottomLineBottomDistance 5
#define TopSelectBtnBottomLineHeight 1
#define TopSelectBtnMiddelLineColor 0x787878
#define TopSelectBtnTextColor 0x5da6ff
#define TopSelectBtnTextColorNormal 0x333333
#define TopSelectBtnTextFont 32/2
#define TopSelectBtnMiddelLineTopDistance 10
#define TopSelectBtnMiddelLineBottomDistance 10
#define TopSelectBtnHeight 30
#define TopSelectBtnTagBegain 0xace66677fff

#define SANSHI 30 //相关按钮隐藏是否需要高度
@interface EvaluateViewController ()<UIAlertViewDelegate>{
    //BOOL  flag;
    UIView *vHead;
    int    addHeight;
    
    UIImageView *_mytransformIV;
    NSInteger _transformFlag;
    UIButton *_titleBtn;
    UILabel *_lab;
    
}
@property(nonatomic,strong)NSMutableArray           *fieldArr;
@property(nonatomic,strong)NSMutableDictionary      *deleDic;
@property(nonatomic,strong)NSMutableDictionary      *addDic;

@property(nonatomic,strong)NSMutableArray           *deleArr;
@property(nonatomic,strong)NSMutableDictionary      *ADDBTN;

@property(nonatomic,strong)NSDictionary             *currentDeleteBtnDic;

@property(nonatomic,strong)NSMutableArray           *searchArr;     // for search words arr

//@property(nonatomic,strong)SearchView *searchView;
@property(nonatomic,strong)UIImageView              *trangle2;

@property(nonatomic,strong)UIImageView              *backImg;
@property(nonatomic,strong)UIAlertView*  alert;
@property(assign,nonatomic)BOOL                     canDelete;
@property(strong, nonatomic)NSMutableArray          *btnArr;
@property(strong, nonatomic)NSMutableArray          *cnName;

@property(strong, nonatomic)NSMutableArray          *detailBtns;
@property(strong, nonatomic)NSArray                 *relationAddSelect; // the select add button to athe  a  new page


@property(assign, nonatomic)BOOL                    write;      // write succeed can take out save data
@property(nonatomic, strong)NSMutableArray          *lineNumberArr;
@property(nonatomic, strong)NSMutableArray          *EvaUrlDateArray;//真实的网络请求评价数据源
@property(nonatomic,strong)UIScrollView *sv;

@property(nonatomic,assign)NSInteger realLength;
@property(nonatomic, assign)NSInteger index;
@end

@implementation EvaluateViewController

static const CGFloat MJDuration = 0.5;

static int begin = 1;
static int limit = 20;
-(void)buttonUrl{
    
}

-(void)setBoolForLeftRight:(BOOL)boolValue{
    if (_NeedLeftAndRightModel == nil) {
        if (boolValue) {
            _NeedLeftAndRightModel = @"YES";
        }else{
            _NeedLeftAndRightModel = @"NO";
        }
    }
}

-(void)viewDidLoad{
    [super viewDidLoad];
    if (_NeedLeftAndRightModel == nil) {
        if (getLeftRightModel()) {
            _NeedLeftAndRightModel = @"YES";
        }else{
            _NeedLeftAndRightModel = @"NO";
        }
    }
    _indexPath = 0;
//    self.lineNumberArr = [NSMutableArray array];
    NSLog(@"%@%@",self.tableId,self.pageId);
    self.EvaUrlDateArray = [[NSMutableArray alloc] init];
    
    begin = 0; // 置 一下 开始 参数 ， 因为 ， 可能不释放 导致 其他页面 获取 从 20  开始 导致 没数据 情况
    [_searchDic removeAllObjects];
    _isSelectedCell = NO;
    _needRefush = YES;
    _index = 0;
    _canDelete = NO;
    
    _ADDBTN = [[NSMutableDictionary alloc]init];
    _titleArr = [NSMutableArray array];
    if (_secondArr) {
        for (NSDictionary *dic in _secondArr) {
            //            substringToIndex
            NSMutableString *strMenuName =[NSMutableString stringWithFormat:@"%@", [dic objectForKey:@"menuName"]];
            if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
                [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
                //                [strMenuName ]
            }
            [_titleArr addObject:strMenuName];
        }
    }

    
    _searchArr = [[NSMutableArray alloc]init];
    NSLog(@"%@",_secondArr);
    if (getLeftRightModel()&&[_NeedLeftAndRightModel isEqualToString:@"YES"]) {
        
        //        if ([getUserType() isEqualToString:UserISHPSStudent]||[getUserType() isEqualToString:UserISHPSTeacher]) {
        
    }else{
        if (_titleArr.count > 1) {
            _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            CGRect frame = CGRectMake(0, 0, 200, 0);
            _titleBtn.frame = frame;
            _lab = [[UILabel alloc] init];
            [_titleBtn addSubview:_lab];
            [_lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(_titleBtn.mas_centerX);
                make.centerY.equalTo(_titleBtn.mas_centerY);
            }];
            _lab.text = [_titleArr firstObject];
            _lab.backgroundColor = [UIColor clearColor];
            _lab.font = [UIFont systemFontOfSize:17];
            _lab.textColor =[UIColor whiteColor];
            [_lab sizeToFit];
            _mytransformIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"often_drop"]];
            [_titleBtn addSubview:_mytransformIV];
            
            [_mytransformIV mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(_titleBtn.mas_centerY).offset(4);
                make.left.equalTo(_lab.mas_right).offset(5);
            }];
            [_titleBtn addTarget:self action:@selector(titleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            self.navigationItem.titleView = _titleBtn;
            self.title = nil;
        }else{
            if (self.menuName) {
                NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", self.menuName];
                if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
                    [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
                }
                
                [self setTitleLabelText:strMenuName];
            }else{
                if (_titleArr.count>0) {
                    [self setTitleLabelText:[_titleArr firstObject]];
                }else{
                    [self setTitleLabelText:@"列表"];
                }
            }
            
        }
        
        
    }
    
    
    //这里添加功能判断
    if (getLeftRightModel()) {
        if (self.menuName) {
            
            NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", self.menuName];
            if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
                [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
            }
            
            [self setTitleLabelText:strMenuName];
        }else{
            [self setTitleLabelText:@"列表"];
        }
    }else{
        
    }
    
    
    
    //    }
    _boolArr = [[NSMutableArray alloc]init];
    _deleteArr = [[NSMutableArray alloc]init];
    _deleArr = [[NSMutableArray alloc]init];
    
    _isPop = @"notPop";
    _deleDic = [[NSMutableDictionary alloc]init];
    
    
    [self createUI];
    
    
    //*** 返回按钮
    [self createLeftNavBar];
    self.tbView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadNewData];
    }];
    
    self.tbView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self footerRefresh];
    }];

//    _titleArr = [NSMutableArray array];
//    if (_secondArr) {
//        for (NSDictionary *dic in _secondArr) {
//            //            substringToIndex
//            NSMutableString *strMenuName =[NSMutableString stringWithFormat:@"%@", [dic objectForKey:@"menuName"]];
//            if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
//                [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
//                //                [strMenuName ]
//            }
//            [_titleArr addObject:strMenuName];
//        }
//    }
//    //    NSString
//    NSLog(@"%@",_titleArr);
////    if (_titleArr.count != 0) {
////        _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
////        CGRect frame = CGRectMake(0, 0, 200, 0);
////        _titleBtn.frame = frame;
////        _lab = [[UILabel alloc] init];
////        [_titleBtn addSubview:_lab];
////        [_lab mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.centerX.equalTo(_titleBtn.mas_centerX);
////            make.centerY.equalTo(_titleBtn.mas_centerY);
////        }];
////        _lab.text = [_titleArr firstObject];
////        _lab.backgroundColor = [UIColor clearColor];
////        _lab.font = [UIFont systemFontOfSize:17];
////        _lab.textColor =[UIColor whiteColor];
////        [_lab sizeToFit];
////        _mytransformIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"often_drop"]];
////        [_titleBtn addSubview:_mytransformIV];
////        
////        [_mytransformIV mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.centerY.equalTo(_titleBtn.mas_centerY).offset(4);
////            make.left.equalTo(_lab.mas_right).offset(5);
////        }];
////        [_titleBtn addTarget:self action:@selector(titleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
////        self.navigationItem.titleView = _titleBtn;
////        self.title = nil;
////    }else{
////        if (self.menuName) {
////            [self setTitleLabelText:self.menuName];
////        }else{
////            [self setTitleLabelText:@"列表"];
////        }
////        
////    }
////    if (_titleArr.count>0) {
////        [self setTitleLabelText:[_titleArr firstObject]];
////    }else{
//        if (self.menuName) {
//            
//            NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", self.menuName];
//            if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
//                [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
//            }
//            
//            [self setTitleLabelText:strMenuName];
//        }else{
//            [self setTitleLabelText:@"列表"];
//        }
////    }
//
//    _boolArr = [[NSMutableArray alloc]init];
//    _deleteArr = [[NSMutableArray alloc]init];
//    _deleArr = [[NSMutableArray alloc]init];
//    
//    _isPop = @"notPop";
//    _deleDic = [[NSMutableDictionary alloc]init];
//    
//    
//    [self createUI];
//    
//    
//    //*** 返回按钮
//    [self createLeftNavBar];
//    self.tbView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        [self loadNewData];
//    }];
//    
//    self.tbView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//        [self footerRefresh];
//    }];
    
    // flag = YES;
    
    [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
    
    
}

#pragma mark - 下拉菜单 ↓

//- (void)selected:(NSInteger)index{
////    _stageDic = [_seleArr objectAtIndex:index];
////    _stageStr = _titles[index];
//    _index = index;
////    [self dataRequest];
//
//}

-(void)titleBtnClick:(UIButton *)sender{
    NSMutableArray *obj = [NSMutableArray array];
    if(self.requeatResultLabel)[self.requeatResultLabel removeFromSuperview];
    if (_isSelectedCell == YES) {
        NSLog(@"return了");
        return;
    }
    for (NSInteger i = 0; i < _titleArr.count; i++) {
        
        WBPopMenuModel * info = [[WBPopMenuModel alloc] init];
        info.image = [self images][i];
        info.title = _titleArr[i];
        [obj addObject:info];
    }
    
    _transformFlag = 0;
    //    [UIView animateWithDuration:0.3
    //                     animations:^{
    //                         _mytransformIV.transform = CGAffineTransformRotate(_mytransformIV.transform, M_PI);
    //                     }];
    
    
    NSInteger myWidth = KWIDTH *0.5;
    
    [[WBPopMenuSingleton shareManager]showPopMenuSelecteWithFrameWidth:myWidth andFrame:CGRectMake(self.view.bounds.size.width-255, 0, 500, 999) item:obj action:^(NSInteger index) {
        NSLog(@"index:%ld",(long)index);
        if (index == 999) {
            if (_transformFlag == 0) {
                //                [UIView animateWithDuration:0.3
                //                                 animations:^{
                //                                     _mytransformIV.transform = CGAffineTransformRotate(_mytransformIV.transform, M_PI);
                //                                 }];
                _transformFlag = 1;
            }
            
            //            btn.enabled = YES;
        }else{
            //            _stageDic = [_seleArr objectAtIndex:index];
            //            _stageStr = _titles[index];
            _index = index;
            begin=0;
            //            [self dataRequest];
            //            [sender setTitle:[self titles][index] forState:UIControlStateNormal];
            _lab.text = _titleArr[index];
            
            NSLog(@"%@，%@",self.pageId,self.tableId);
            
            //            NSLog(@"%@",_secondArr);
            NSDictionary *selectDic = [_secondArr objectAtIndex:index];
            NSString *pageId = [selectDic objectForKey:@"pageId"];
            NSString *tableId = [selectDic objectForKey:@"tableId"];
            NSLog(@"%@, %@",pageId,tableId);
            self.pageId = pageId;
            self.tableId = tableId;
            [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
            if (_transformFlag == 0) {
                //                [UIView animateWithDuration:0.3
                //                                 animations:^{
                //                                     _mytransformIV.transform = CGAffineTransformRotate(_mytransformIV.transform, M_PI);
                //                                 }];
                _transformFlag = 1;
            }
            
            //            [self popAc:index];
        }
        
    }];
    
}

#pragma mark -POPVC


- (NSArray *) images {
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    for (int i = 0; i < _titleArr.count; i ++ ) {
        [arr addObject:@"often_drop_curriculum"];
    }
#pragma mark - 取出图片就nil，不去就return arr;
    return nil;
    return arr;
    
}


#pragma mark - 下拉菜单end ↑


- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
    
    //通过[previewingContext sourceView]拿到对应的cell的数据；
    NSIndexPath *indexPath = [self.tbView indexPathForCell:(EvaluateTableViewCell *)[previewingContext sourceView]];
    // 用于显示预览的vc
    ListDetailViewController *listDVC = [[ListDetailViewController alloc] init];
    listDVC.retureView = self;
    listDVC.cnName = _cnName;
    listDVC.buttons = _detailBtns;
    listDVC.tableId = self.tableId;
    listDVC.pageId = self.pageId;
    
    listDVC.dataDic = self.dataDic;
    listDVC.ADDBTN = _ADDBTN;
    self.isPop = @"detail";
    
    
    NSDictionary *dic= [_fieldArr objectAtIndex:indexPath.row];
    listDVC.detailDic = dic;
    
    return listDVC;
}
//- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
//{
//    // check if we're not already displaying a preview controller
//    //SecViewController 是要弹出悬浮展示的ViewController
//    if ([self.presentedViewController isKindOfClass:[ListDetailViewController class]]) {
//        return nil;
//    }
//    EvaluateTableViewCell *cell = (EvaluateTableViewCell *)previewingContext.sourceView;
//
//    ListDetailViewController *listDVC = [[ListDetailViewController alloc] init];
//    listDVC.retureView = self;
//    listDVC.cnName = _cnName;
//    listDVC.buttons = _detailBtns;
//    listDVC.tableId = self.tableId;
//    listDVC.pageId = self.pageId;
//
//    listDVC.dataDic = self.dataDic;
//    listDVC.ADDBTN = _ADDBTN;
//    self.isPop = @"detail";
//
//
//    NSDictionary *dic= [_fieldArr objectAtIndex:cell.indexPath.row];
//    listDVC.detailDic = dic;
//
//    return listDVC;
//
//}

-(void)searchReloadData:(NSNotification *)n{
    NSArray *arr = [n object];
    _fieldArr = [NSMutableArray arrayWithArray:arr];
    [self.tbView reloadData];
}

#pragma mark - while addSucceed or changed succeed should reload Data
-(void)reloadListView:(NSNotification *)noti{
    
    self.shouldReloadList = SHOULDRELOAD;
}
#pragma mark - Refresh
-(void)loadNewData{
    
    _searchDic = nil;
    
    
    [self.tbView.header beginRefreshing];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(MJDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        //*** setting edit style
        
        [self setStyle];
        
        // 刷新表格
        begin = 0;
        [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
        
        // 拿到当前的下拉刷新控件，结束刷新状态
        [self.tbView.header endRefreshing];
    });
    
}

#pragma mark - Refresh
-(void)footerRefresh{
    [self.tbView.footer beginRefreshing];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(MJDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        //*** setting edit style
        
        [self setStyle];
        
        // 刷新表格
        begin += limit;
        [self dataRequestWithBegining:begin andLimit:limit andIsFooter:YES];
        
        // 拿到当前的下拉刷新控件，结束刷新状态
        [self.tbView.footer endRefreshing];
    });
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    self.cusTabView.userInteractionEnabled = NO;
    //*** the notifications
    
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:YES];
    self.cusTabView.userInteractionEnabled = YES;
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if(self.completeBtn!=nil&&self.completeBtn.hidden == NO)
    {
        self.completeBtn.enabled = YES;
    }
    if (_isSelectedCell == YES) {
        _isSelectedCell = NO;
    }
    self.cusTabView.hidden = YES;
    if (!_testDataArray) {
        self.testDataArray = [[NSMutableArray alloc] init];
    }
    //*** the notifications
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reloadListView:) name:SHOULDRELOAD object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(searchReloadData:) name:@"row" object:nil];
    
    
    //        NSInteger forCount = 13;
    //        NSMutableArray *count ;
    if (self.lineNumberArr == nil) {
        self.lineNumberArr = [[NSMutableArray alloc] init];
    }
    
    
//    NSArray *evaArray =@[@"备课认真",@"教学专业",@"讲解清晰",@"穿着正式",@"语速过快",@"着装邋遢",@"耐心负责",@"上课玩手机",@"备课不认真",@"上课缺少互动",@"迟到",@"早退",@"上课无计划"];
//    NSLog(@"%@",evaArray);
    
//    for (int i = 0; i < 20; i++) {
//        NSInteger forCount = arc4random() % 10+3;
//        NSMutableArray *realEvaArr = [NSMutableArray array];
//        for (int i = 0; i < forCount; i++) {
//            NSInteger arrCount = arc4random() % evaArray.count+0;
//            //        [count addObject:[NSString stringWithFormat:@"%zd",arrCount]];
//            [realEvaArr addObject:[evaArray objectAtIndex:arrCount]];
//        }
//        [_testDataArray addObject:realEvaArr];
//    }
    NSLog(@"%@",self.testDataArray);
//    _testDataArray
    
    
    
//    for (int j = 0; j < 20; j++) {
//        NSInteger lineNumber = 1;
//        NSString *allLenth = [NSString string];
//        NSString *beforeLenth = [NSString string];
//        NSMutableArray *FrameArr = [[NSMutableArray alloc] init];
//        int k = 0;
//        for (int i = 0; i < [[_testDataArray objectAtIndex:j] count]; i++) {
//            allLenth = [NSString stringWithFormat:@"%@%@",allLenth,[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
//            CGRect rect = [allLenth boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
//            NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
//            CGFloat lineBeyond = ceil(lenth/(KWIDTH-45));
//            if (lineBeyond == 2) {
//                allLenth = [NSString stringWithFormat:@"%@",[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
//                beforeLenth = [NSString stringWithFormat:@"%@",[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
//                lineNumber++;
//                k = 0;
//                
//                CGRect rect = [allLenth boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
//                NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
//                NSString *topStr = [NSString stringWithFormat:@"%ld",(224+22+(lineNumber-1)*(52+22))/2];
//                NSString *rightStr = [NSString stringWithFormat:@"%d",50/2];
//                
//                [FrameArr addObject:@[topStr,@"1"]];
//            }else{
//                CGRect rect;
//                if (i == 0||k==0) {
//                    rect = CGRectMake(0, 0, 0, 0);
//                }else{
//                    rect = [beforeLenth boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
//                }
//                beforeLenth = [NSString stringWithFormat:@"%@%@",beforeLenth,[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
//                NSString *topStr = [NSString stringWithFormat:@"%ld",(224+22+(lineNumber-1)*(52+22))/2];
//                NSString *rightStr = [NSString stringWithFormat:@"%f",50/2+rect.size.width+k*(14+22)/2];
//                
//                [FrameArr addObject:@[topStr,@"0"]];
//                
//                
//                k++;
//            }
//            
//            
//            
//        }
//        [_lineNumberArr addObject:[NSString stringWithFormat:@"%ld",(long)lineNumber]];
//        
//
//    }
    
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:YES];
    
    if (!self.needRefush) {
        self.needRefush = !self.needRefush;
        
        return;
    }
    //NSString *ft = [NSString stringWithFormat:@"%@",_fieldTIme];
    //NSString *dt = [NSString stringWithFormat:@"%@",_dataTime];
    //NSString *ot = [NSString stringWithFormat:@"%@",_operaTIme];
    //NSString *bt = [NSString stringWithFormat:@"%@",_btnTime];
    
    //![ft isEqualToString:FieldTime()]||![ot isEqualToString:Operatime()]||![bt isEqualToString:BtnTime()]||![dt isEqualToString:datatime()]||
    if([self.shouldReloadList isEqualToString:SHOULDRELOAD]){
        
        begin = 0;
        [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
        //saveDataTime(dt);
        //saveFieldTime(ft);
        //saveOperaTime(ot);
        //saveBtnSetTime(bt);
    }
    else{
        if(!_write)return;
        NSString *path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        NSString *path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listFor%@%@.plist", self.tableId, self.pageId]];
        
        NSDictionary *saveDic = [NSDictionary dictionaryWithContentsOfFile:path3];
        NSMutableArray *currwntDataArr = [NSMutableArray arrayWithArray:[saveDic objectForKey:@"dataList"]];
        if (currwntDataArr) {
            _fieldArr = [[NSMutableArray alloc]initWithArray:currwntDataArr];
        }
        if([saveDic valueForKey:@"pageSet"]!=nil)_cnName = [[NSMutableArray alloc]initWithArray:[[saveDic valueForKey:@"pageSet"]valueForKey:@"fieldSet"]];
        if([saveDic valueForKey:@"pageSet"])_btnArr = [[saveDic valueForKey:@"pageSet"] valueForKey:@"buttonSet"];
        
        //         _fieldArr = [NSMutableArray arrayWithContentsOfFile:path3];
        [self createBoolArr];
        
        self.longSelected = NO;
        
        
        
    }
    
}


-(void)createLeftNavBar{
    UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBtn = leftNavBtn;
    
    if (!self.longSelected) {
        [self.leftBtn setImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
        [self.leftBtn setTitle:@"" forState:UIControlStateNormal];
        self.leftBtn.frame = CGRectMake(0, 0, 11, 37/2);
        
    }else{
        [self.leftBtn setTitle:@"取消" forState:UIControlStateNormal];
        [self.leftBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.leftBtn.frame = CGRectMake(0, 0, 50, 37/2);
        
    }
    
    [self.leftBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:self.leftBtn];
    self.navigationItem.leftBarButtonItem = item;
    
}

#pragma mark - setRithgAndUITableViewEditStyle
-(void)setStyle{
    if (self.longSelected) {
        self.longSelected = !self.longSelected;
        [self setRightBtn];
        
        self.tbView.editing = NO;
        [self.tbView reloadData];
        //        for (int i = 0; i<self.deleArr.count; i++) {
        //            [self.boolArr replaceObjectAtIndex:i withObject:@"NO"];
        //        }
        [self createBoolArr];
        
        //*** whill deleted or exit dselete shoule remove all object in delete arr
        [self.deleArr removeAllObjects];
    }
}
-(void)LeftClick:(UIButton *)btn{
    if (self.longSelected) {
        
        //*** for set selectionstyle
        [self setStyle];
    }else{
        
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}
-(void)dataRequestWithBegining:(int)begin andLimit:(int)limit andIsFooter:(BOOL)is{
    
    
    if(self.longSelected){
        //*** setting right and left btn for editing style
        self.longSelected = NO;
        [self setRightBtn];
        
        //*** every cell have a bool value to make sure it is edit or normal here to edit the bool arr
        [self createBoolArr];
        
        //*** whill deleted or exit dselete shoule remove all object in delete arr
        [self.deleArr removeAllObjects];
    }
    
    NSString *requestUrl;
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    NSDictionary *saveDic;
    NSDictionary *savePageSetDic;
    NSString *path3;
    NSString *pathForPageSet;
    
    if(!_fromThings){
        //*** take out the save data path
        NSString *path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listFor%@%@.plist", self.tableId, self.pageId]];
        
        pathForPageSet = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listFor%@%@pageSet.plist", self.tableId, self.pageId]];
        
        NSData *saveData = [NSData dataWithContentsOfFile:path3];
        if(saveData) saveDic = [NSJSONSerialization JSONObjectWithData:saveData options:NSJSONReadingMutableContainers error:nil];
        savePageSetDic = [[NSDictionary alloc]initWithContentsOfFile:pathForPageSet];
        
        [parmas setObject:userName() forKey:@"loginName"];
        [parmas setObject:passWord() forKey:@"password"];
        
        //*** wheather the tableId pageId is used
        if(self.pageId)[parmas setObject:self.pageId forKey:@"pageId"];
        if(self.tableId)[parmas setObject:self.tableId forKey:@"tableId"];
        
        //*** if have alterTime use the alterTime else use nil
        if([saveDic valueForKey:@"000"]){
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        [parmas setObject:@"" forKey:@"alterTime"];
        
        
        [parmas setObject:[NSString stringWithFormat:@"%i", limit] forKey:@"limit"];
        [parmas setObject:[NSString stringWithFormat:@"%i", begin] forKey:@"start"];
        
        //    NSString *requestStr =getUrl(List_URL);
        
        if(_searchDic.count>0){
            parmas = [[NSMutableDictionary alloc]initWithDictionary:self.searchDic];
            [parmas setObject:[NSString stringWithFormat:@"%i", limit] forKey:@"limit"];
            [parmas setObject:[NSString stringWithFormat:@"%i", begin] forKey:@"start"];
            
            //        NSString *limitStr = [NSString stringWithFormat:@"%@", [self.searchDic valueForKey:@"start"]];
        }
        
        requestUrl = [NSString stringWithFormat:@"%@%@", self.programaUrl, LISTSVIEWREQUEST_URL];
        
    }else{
        //*** take out the save data path
        NSString *path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listFor%@%@.plist", self.tableId, self.pageId]];
        
        pathForPageSet = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listFor%@%@pageSet.plist", self.tableId, self.pageId]];
        
        NSData *saveData = [NSData dataWithContentsOfFile:path3];
        if(saveData)saveDic = [NSJSONSerialization JSONObjectWithData:saveData options:NSJSONReadingMutableContainers error:nil];
        savePageSetDic = [[NSDictionary alloc]initWithContentsOfFile:pathForPageSet];
        
        if (self.pageId&&self.tableId) {
            [parmas setObject:_model.phonePageId forKey:@"pageId"];
            [parmas setObject:_model.tableId forKey:@"tableId"];
        }else{
            [parmas setObject:_model.phonePageId forKey:@"pageId"];
            [parmas setObject:_model.tableId forKey:@"tableId"];
        }
        
        
        
        
        [parmas setObject:[NSString stringWithFormat:@"%i", limit] forKey:@"limit"];
        [parmas setObject:[NSString stringWithFormat:@"%i", begin] forKey:@"start"];
        
        //    NSString *requestStr =getUrl(List_URL);
        
        if(_searchDic.count>0){
            parmas = [[NSMutableDictionary alloc]initWithDictionary:self.searchDic];
            [parmas setObject:[NSString stringWithFormat:@"%i", limit] forKey:@"limit"];
            [parmas setObject:[NSString stringWithFormat:@"%i", begin] forKey:@"start"];
            
            //        NSString *limitStr = [NSString stringWithFormat:@"%@", [self.searchDic valueForKey:@"start"]];
        }
        
        NSString *strSD = [NSString stringWithFormat:@"%@_%@", _model.homeSetId, _model.index];
        [parmas setObject:strSD forKey:@"SourceDataId"];
        requestUrl = [NSString stringWithFormat:@"%@%@", self.programaUrl, SHIWUKANBAN];
        
    }
    
    
    [NetRequest requestUrl:requestUrl andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        
        //*** saveCurrArr
        NSMutableArray *btnArr = [[NSMutableArray alloc]init];
        
        self.shouldReloadList = @"loading";
        if(data !=nil&&!error){
            
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            [self dataUse:obj andSaveDic:saveDic andButtonArr:btnArr andIsFooter:is andWritePath:path3 andPagePath:pathForPageSet andPageSetDic:savePageSetDic];
            
            [data writeToFile:path3 atomically:YES];
            
            //            NSLog(@"%@",obj);
            
            
        }else{
            
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            [self dataUse:saveDic andSaveDic:saveDic andButtonArr:btnArr andIsFooter:is andWritePath:path3 andPagePath:pathForPageSet andPageSetDic:savePageSetDic];
            
        }
        
    }];
    
    
}


-(void)dataUse:(id)obj andSaveDic:(NSDictionary *)saveDic andButtonArr:(NSMutableArray *)btnArr andIsFooter:(BOOL)is andWritePath:(NSString *)path3 andPagePath:(NSString *)pagePath andPageSetDic:(NSDictionary *)pageSetSaveDic{
    //*** take the data to the data arr and page cN_Pl name
    NSLog(@"%@", [[[obj valueForKey:@"pageSet"]valueForKey:@"fieldSet"][0]valueForKey:@"fieldCnName"]);
    NSMutableArray *currwntDataArr = [NSMutableArray arrayWithArray:[obj objectForKey:@"dataList"]];
    if([obj valueForKey:@"pageSet"]!=nil){
        
        _cnName = [[NSMutableArray alloc]initWithArray:[[obj valueForKey:@"pageSet"]valueForKey:@"fieldSet"]];
        
    }
    if(_cnName == nil){
        if(pageSetSaveDic)_cnName = [[NSMutableArray alloc]initWithArray:[pageSetSaveDic valueForKey:@"fieldSet"]];
    }
    if([obj valueForKey:@"pageSet"]){
        btnArr = [[obj valueForKey:@"pageSet"] valueForKey:@"buttonSet"];
        self.searchArr = [[obj valueForKey:@"pageSet"] valueForKey:@"serachSet"];
        //*** setting right button can use
#warning these kind of code mast cahnge rewrite
        NSMutableArray *btnArrU = [[NSMutableArray alloc]initWithArray:btnArr];
        
        for (NSDictionary *dic in btnArrU) {
            NSString *str = [NSString stringWithFormat:@"%@_%@", self.pageId, [dic valueForKey:@"buttonId"]];
            BOOL can = textButton(str);
            if (!can&&![userName() isEqualToString:@"admin"]) {
                [btnArr removeObject:dic];
            }
        }
        
        
        _btnArr = btnArr; // 列表页显示按钮
        
        //*** detail
        NSMutableArray *btnArrDetail = [[obj valueForKey:@"pageSet"] valueForKey:@"operaButtonSet"];
        
        NSMutableArray *btnArrDetailU = [[NSMutableArray alloc]initWithArray:btnArrDetail];
        for (NSDictionary *dic in btnArrDetailU) {
            NSString *str = [NSString stringWithFormat:@"%@_%@", self.pageId, [dic valueForKey:@"buttonId"]];
            BOOL can = textButton(str);
            if (!can&&![userName() isEqualToString:@"admin"]) {
                [btnArrDetail removeObject:dic];
            }
        }
        
        
        _detailBtns = btnArrDetail;
        
        if(btnArr.count>0){
            self.canDelete = YES;
        }
        
        if([obj valueForKey:@"pageSet"]){
            _relationAddSelect = [[NSArray alloc]initWithArray:[[obj valueForKey:@"pageSet"] valueForKey:@"childTabs"]];
        }
        
        
        //*** 添加项目按钮
        [self createRightNavBar];
    }
    if(_relationAddSelect == nil){
        if(pageSetSaveDic)_relationAddSelect = [[NSArray alloc]initWithArray:[pageSetSaveDic  valueForKey:@"childTabs"]];
    }
    if (_relationAddSelect.count<=0) {
        addHeight = 0;
    }else{
        addHeight = SANSHI;
    }
    //*** no bu r
    if(btnArr.count<=0||self.searchArr.count<=0||_detailBtns.count<=0){
        if (btnArr.count <=0) {
            btnArr = [pageSetSaveDic valueForKey:@"buttonSet"];
            
            NSMutableArray *btnArrU = [[NSMutableArray alloc]initWithArray:btnArr];
            
            for (NSDictionary *dic in btnArrU) {
                NSString *str = [NSString stringWithFormat:@"%@_%@", self.pageId, [dic valueForKey:@"buttonId"]];
                BOOL can = textButton(str);
                if (!can) {
                    [btnArr removeObject:btnArrU];
                }
            }
            
            
            _btnArr = btnArr;
            
        }
        
        if(_detailBtns.count<=0){
            NSMutableArray *btnArrDetail = [pageSetSaveDic valueForKey:@"operaButtonSet"];
            
            NSMutableArray *btnArrDetailU = [[NSMutableArray alloc]init];
            
            for (NSDictionary *dic in btnArrDetailU) {
                NSString *str = [NSString stringWithFormat:@"%@_%@", self.pageId, [dic valueForKey:@"buttonId"]];
                BOOL can = textButton(str);
                if (!can&&![userName() isEqualToString:@"admin"]) {
                    [btnArrDetail removeObject:dic];
                }
            }
            
            
            _detailBtns = btnArrDetail;
            
        }
        if(self.searchArr.count<=0){
            self.searchArr = [pageSetSaveDic valueForKey:@"serachSet"];
        }
        
        if(btnArr.count>0){
            self.canDelete = YES;
        }
        
        //*** 添加项目按钮
        [self createRightNavBar];
        
    }
    if (is) {
        for (id obj in currwntDataArr) {
//            [_EvaUrlDateArray removeAllObjects];
            [_fieldArr addObject:obj];

        }
        [_EvaUrlDateArray removeAllObjects];
        for (int i = 0 ;i < _fieldArr.count ; i++) {
            
            BOOL ishaveEVA = NO;
            NSMutableArray *arr;
            
            
            arr =[NSMutableArray arrayWithArray:_fieldArr];
            NSDictionary *dic = [arr objectAtIndex:i];
            
            NSArray *arrqqqqq = [dic allKeys];
            arrqqqqq = [arrqqqqq sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
                NSComparisonResult result = [obj1 compare:obj2];
                return result==NSOrderedDescending;
            }];
            
            for (id IDA in arrqqqqq) {
                
                
                
                NSString *strA = [NSString stringWithFormat:@"%@", IDA];
                NSLog(@"%@",strA);
                if(_cnName.count> 5){
                    NSString *testStr = [NSString stringWithFormat:@"%@", [[_cnName lastObject] valueForKey:@"fieldAliasName"]] ;
                    NSLog(@"%@",testStr);
                    
                    if ([testStr isEqualToString:strA]) {
                        NSString *contentStr = [NSString stringWithFormat:@"%@", [dic valueForKey:strA]];
                        
                        
                        
                        //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
                        NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
                        
                        //&&![_dic valueForKey:strA]
                        if([[dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![dic valueForKey:strA]){
                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
                            
                            [_EvaUrlDateArray addObject:evaArr];
                            ishaveEVA = YES;
                        }else{
                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
                            
                            [_EvaUrlDateArray addObject:evaArr];
                            ishaveEVA = YES;
                        }
                        
                        
                        NSLog(@"contentStr:%@",contentStr);
                    }
//                    testStr = [NSString stringWithFormat:@"%@", [[_cnName objectAtIndex:_cnName.count-2] valueForKey:@"fieldAliasName"]] ;
//                    NSLog(@"%@",testStr);
//                    
//                    if ([testStr isEqualToString:strA]) {
//                        NSString *contentStr = [NSString stringWithFormat:@"%@", [dic valueForKey:strA]];
//                        
//                        
//                        
//                        //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
//                        NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
//                        
//                        //&&![_dic valueForKey:strA]
//                        if([[dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![dic valueForKey:strA]){
//                            contentStr =[NSString stringWithFormat:@"%@", [dic objectForKey:lastStr]];
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }else{
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }
//                        
//                        
//                        NSLog(@"contentStr:%@",contentStr);
//                    }
//                    testStr = [NSString stringWithFormat:@"%@", [[_cnName objectAtIndex:_cnName.count-3] valueForKey:@"fieldAliasName"]] ;
//                    NSLog(@"%@",testStr);
//                    
//                    if ([testStr isEqualToString:strA]) {
//                        NSString *contentStr = [NSString stringWithFormat:@"%@", [dic valueForKey:strA]];
//                        
//                        
//                        
//                        //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
//                        NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
//                        
//                        //&&![_dic valueForKey:strA]
//                        if([[dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![dic valueForKey:strA]){
//                            contentStr =[NSString stringWithFormat:@"%@", [dic objectForKey:lastStr]];
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }else{
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }
//                        
//                        
//                        NSLog(@"contentStr:%@",contentStr);
//                    }
//                    
//                    testStr = [NSString stringWithFormat:@"%@", [[_cnName objectAtIndex:_cnName.count-4] valueForKey:@"fieldAliasName"]] ;
//                    NSLog(@"%@",testStr);
//                    
//                    if ([testStr isEqualToString:strA]) {
//                        NSString *contentStr = [NSString stringWithFormat:@"%@", [dic valueForKey:strA]];
//                        
//                        
//                        
//                        //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
//                        NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
//                        
//                        //&&![_dic valueForKey:strA]
//                        if([[dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![dic valueForKey:strA]){
//                            contentStr =[NSString stringWithFormat:@"%@", [dic objectForKey:lastStr]];
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }else{
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }
//                        
//                        
//                        NSLog(@"contentStr:%@",contentStr);
//                    }
//                    
//                    testStr = [NSString stringWithFormat:@"%@", [[_cnName objectAtIndex:_cnName.count-5] valueForKey:@"fieldAliasName"]] ;
//                    NSLog(@"%@",testStr);
//                    
//                    if ([testStr isEqualToString:strA]) {
//                        NSString *contentStr = [NSString stringWithFormat:@"%@", [dic valueForKey:strA]];
//                        
//                        
//                        
//                        //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
//                        NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
//                        
//                        //&&![_dic valueForKey:strA]
//                        if([[dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![dic valueForKey:strA]){
//                            contentStr =[NSString stringWithFormat:@"%@", [dic objectForKey:lastStr]];
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                        }else{
//                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
//                            
//                            [_EvaUrlDateArray addObject:evaArr];
//                            ishaveEVA = YES;
//                            
//                        }
//                        
//                        
//                        NSLog(@"contentStr:%@",contentStr);
//                    }
                    
                    
                    
                }
                
                
                
                
            }
            if (ishaveEVA == NO) {
                [_EvaUrlDateArray addObject:[NSArray arrayWithObject:@""]];
            }
            
            //for循环结束的地方
        }
        
    }else{
        _fieldArr = [NSMutableArray arrayWithArray:currwntDataArr];
        [_EvaUrlDateArray removeAllObjects];
        for (int i = 0 ;i < _fieldArr.count ; i++) {
           
            BOOL ishaveEVA = NO;
            NSMutableArray *arr;
            arr =[NSMutableArray arrayWithArray:_fieldArr];
            NSDictionary *dic = [arr objectAtIndex:i];
            
            NSArray *arrqqqqq = [dic allKeys];
            arrqqqqq = [arrqqqqq sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
                NSComparisonResult result = [obj1 compare:obj2];
                return result==NSOrderedDescending;
            }];
            
            for (id IDA in arrqqqqq) {
                
                
                
                NSString *strA = [NSString stringWithFormat:@"%@", IDA];
                NSLog(@"%@",strA);
                if(_cnName.count> 5){
                    NSString *testStr = [NSString stringWithFormat:@"%@", [[_cnName lastObject] valueForKey:@"fieldAliasName"]] ;
                    NSLog(@"%@",testStr);
                    
                    if ([testStr isEqualToString:strA]) {
                        NSString *contentStr = [NSString stringWithFormat:@"%@", [dic valueForKey:strA]];
                        
                        
                        
                        //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
                        NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
                        
                        //&&![_dic valueForKey:strA]
                        if([[dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![dic valueForKey:strA]){
                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
                            
                            [_EvaUrlDateArray addObject:evaArr];
                            ishaveEVA = YES;
                        }else{
                            NSArray *evaArr = [contentStr componentsSeparatedByString:@","];
                            
                            [_EvaUrlDateArray addObject:evaArr];
                            ishaveEVA = YES;
                        }
                        
                        
                        NSLog(@"contentStr:%@",contentStr);
                    }
                }
                
                
                
                
            }
            if (ishaveEVA == NO) {
                [_EvaUrlDateArray addObject:[NSArray arrayWithObject:@""]];
            }
            
            //for循环结束的地方
        }
        
    }
    _testDataArray = _EvaUrlDateArray;
    [self createCellHeight];
    //*** old other write now change
    
    //*** the new one write all data to a the save path for now
    //_write = [obj writeToFile:path3 atomically:YES];
    //[[obj valueForKey:@"pageSet"]writeToFile:pagePath atomically:YES];
    
    
    //*** the bool arr is for delete tap
    [self createBoolArr];
    NSString *NOMoreStr;
    NSString *NODataStr;
    if ([getUserType() isEqualToString:UserISHPSTeacher]) {
        NOMoreStr = @"No more data";
        NODataStr = @"No data";
    }else{
        NOMoreStr = @"本页无更多数据";
        NODataStr = @"本页无数据";
    }
    if (is&&currwntDataArr.count==0) {
        [self showLabelWithText:NOMoreStr];
        begin -= limit; // 无更多数据的时候将 begin 置回 之前的 数据状态
    }else if(currwntDataArr.count==0){
        [self showLabelWithText:NODataStr];
    }
    self.longSelected = NO;
    
}

- (void)createCellHeight{
    [_lineNumberArr removeAllObjects];
    for (int j = 0; j < _testDataArray.count; j++) {
        NSInteger lineNumber = 1;
        NSString *allLenth = [NSString string];
        NSString *beforeLenth = [NSString string];
        NSMutableArray *FrameArr = [[NSMutableArray alloc] init];
        int k = 0;
        if ([[[_testDataArray objectAtIndex:j] firstObject] isEqualToString:@""]) {
            lineNumber = 0;
        }
        for (int i = 0; i < [[_testDataArray objectAtIndex:j] count]; i++) {
            
            allLenth = [NSString stringWithFormat:@"%@%@",allLenth,[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
            CGRect rect = [allLenth boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
            NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
            CGFloat lineBeyond = ceil(lenth/(KWIDTH-45));
            if (lineBeyond == 2) {
                allLenth = [NSString stringWithFormat:@"%@",[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
                beforeLenth = [NSString stringWithFormat:@"%@",[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
                lineNumber++;
                k = 0;
                
//                CGRect rect = [allLenth boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
//                NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
                NSString *topStr = [NSString stringWithFormat:@"%ld",(224+22+(lineNumber-1)*(52+22))/2];
//                NSString *rightStr = [NSString stringWithFormat:@"%d",50/2];
                
                [FrameArr addObject:@[topStr,@"1"]];
            }else{
                CGRect rect;
                if (i == 0||k==0) {
                    rect = CGRectMake(0, 0, 0, 0);
                }else{
                    rect = [beforeLenth boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
                }
                beforeLenth = [NSString stringWithFormat:@"%@%@",beforeLenth,[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
                NSString *topStr = [NSString stringWithFormat:@"%ld",(224+22+(lineNumber-1)*(52+22))/2];
//                NSString *rightStr = [NSString stringWithFormat:@"%f",50/2+rect.size.width+k*(14+22)/2];
                
                [FrameArr addObject:@[topStr,@"0"]];
                
                
                k++;
            }
            
            
            
        }
        [_lineNumberArr addObject:[NSString stringWithFormat:@"%ld",(long)lineNumber]];
        
        
    }
}


-(void)createBoolArr{
    if(_fieldArr != nil){
        [self.boolArr removeAllObjects];
        for (int i = 0; i < _fieldArr.count; i++) {
            [self.boolArr addObject:@"NO"];
        }
        
        self.longSelected = NO;
        [self.tbView reloadData];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0; // TABLEVIEWHEADERHEIGHT
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    vHead =[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
    vHead.backgroundColor =[UIColor yellowColor];
    
    
    //*** shaixuan btn
    UIButton *searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    
    [vHead addSubview:searchBtn];
    searchBtn.backgroundColor =[UIColor whiteColor];
    
    [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(vHead.mas_left);
        
        make.top.equalTo(vHead.mas_top);
        make.right.equalTo(vHead.mas_right);
        make.height.equalTo(@(86/2));
    }];
    //    [searchBtn setTitle:@"筛选" forState:UIControlStateNormal];
    [searchBtn setImage:[UIImage imageNamed:@"搜索_"] forState:UIControlStateNormal];
    [searchBtn setImage:[UIImage imageNamed:@"搜索点击状态_"] forState:UIControlStateHighlighted];
    
    [searchBtn addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
    [searchBtn setTitleColor:[UIColor colorWithHex:0x636363] forState:UIControlStateNormal];
    searchBtn.titleLabel.font =[UIFont systemFontOfSize:15];
    
    return vHead;
    
}

-(void)allClick:(UIButton *)btn{
    begin = 0;
    [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
}

#pragma mark ====旋转动画======
//-(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount
//{
//  CATransform3D rotationTransform = CATransform3DMakeRotation(degree, 0, 0, direction);
//CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
//animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
//animation.duration  =  dur;
//animation.autoreverses = NO;
//animation.cumulative = NO;
//animation.fillMode = kCAFillModeForwards;
//animation.repeatCount = repeatCount;
//animation.delegate = self;

//return animation;
//
//}



-(void)createRightNavBar{
    
    static  UIButton *rightNavBtn;
    rightNavBtn= [[UIButton alloc]init];
    rightNavBtn.frame = CGRectMake(0, 0, 25, 25);
    [rightNavBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:rightNavBtn];
    self.normalBtn = item;
    self.completeBtn = rightNavBtn;
    [self setRightBtn];
    self.navigationItem.rightBarButtonItem = self.normalBtn;
    
}

-(void)setRightBtn{
    //*** mark for sub to the svn
    if (!self.longSelected) {
        [self.completeBtn setImage:[UIImage imageNamed:@"更多操作_"] forState:UIControlStateNormal];
        [self.completeBtn setTitle:@"" forState:UIControlStateNormal];
        [self.leftBtn setImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
        [self.leftBtn setTitle:@"" forState:UIControlStateNormal];
        self.leftBtn.frame = CGRectMake(0, 0, 11, 37/2);
        if(self.btnArr.count<=0)self.completeBtn.hidden = YES;
        self.completeBtn.frame = CGRectMake(0, 0, 25, 25);
        
        
        
    }else{
        self.completeBtn.hidden = NO;
        [self.completeBtn setTitle:@"删除" forState:UIControlStateNormal];
        [self.completeBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [self.leftBtn setTitle:@"取消" forState:UIControlStateNormal];
        [self.leftBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.leftBtn.frame = CGRectMake(0, 0, 50, 37/2);
        self.completeBtn.frame = CGRectMake(0, 0, 50, 37/2);
        
        
    }
}

-(void)rightClick:(UIButton *)btn{
    btn.enabled = NO;
    if(self.longSelected){
        if(_deleArr.count==0){
            if (CURRENTVERSION<9.0) {
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"注意" message:@"请选择至少一项" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                
                [alert show];
            }else{
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"注意" message:@"请选择至少一项" preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *cancelAction1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                    NSLog(@"delete");
                    
                    btn.enabled = YES;
                    
                    
                }];
                
                [alertController addAction:cancelAction1];
                [self presentViewController:alertController animated:YES completion:^{
                    
                }];
                
            }
            return;
            
        }
        //
        
        if (CURRENTVERSION<9.0) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"删除学员" message:@"注意:当你点删除时,数据库中也会同步删除" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除", nil];
            
            [alert show];
        }else{
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"删除学员" message:@"注意:当你点删除时,数据库中也会同步删除" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *cancelAction1 = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"delete");
                self.longSelected = !self.longSelected;
                [self deleRequest:self.completeBtn];
                btn.enabled = YES;
                
                
            }];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //                [self createBoolArr];
                //                [_deleArr removeAllObjects];
                
                
            }];
            [alertController addAction:cancelAction];
            [alertController addAction:cancelAction1];
            [self presentViewController:alertController animated:YES completion:^{
                
            }];
            self.completeBtn.enabled = YES;
            
        }
        
    }else{
        UIActionSheet *actionSheet;
        //这里添加功能判断
        if (getEnglishLanguage()) {
            actionSheet = [[UIActionSheet alloc]initWithTitle:@"More" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
        }else{
            actionSheet = [[UIActionSheet alloc]initWithTitle:@"更多操作" delegate:self cancelButtonTitle:@"返回" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
        }
        
        
        
        for(NSDictionary *dic in _btnArr){
            [actionSheet addButtonWithTitle:[dic objectForKey:@"buttonName"]];
        }
        
        
        [actionSheet showInView:self.view];
    }
}

#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    NSLog(@"%ld", (long)buttonIndex);
    self.completeBtn.enabled = YES;
    //    if([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"添加"])[self popAc:0];
    
    
    if(buttonIndex == 0){
        return;
    }
    NSDictionary *dic = _btnArr[buttonIndex-1];
    
    _currentDeleteBtnDic = dic;
    
    if ([[NSString stringWithFormat:@"%@", [dic valueForKey:@"buttonType"]]isEqualToString:@"12"]) {
        //        [self editStyleBtnClick:dic];
    }else if([[NSString stringWithFormat:@"%@", [dic valueForKey:@"buttonType"]]isEqualToString:@"13"]){
        [self deleteBtnClick:dic];
    }else if([[NSString stringWithFormat:@"%@", [dic valueForKey:@"buttonType"]]isEqualToString:@"0"]){
        [self addBtnClick:dic];
        //        [self popAc:0];
    }else if([[NSString stringWithFormat:@"%@", [dic valueForKey:@"buttonType"]]isEqualToString:@"3"]){
        
        self.canDelete = YES;
        [self longPressClick];
    }
    NSLog(@"%@", _btnArr);
    
}


-(void)deleteBtnClick:(NSDictionary *)dic{
    
    if(!self.canDelete)return;
    if(self.longSelected){
        NSLog(@"a");return;
    }
    self.longSelected = !self.longSelected;
    
    [self setRightBtn];
    [self.tbView reloadData];
    
    
}

-(void)addBtnClick:(NSDictionary *)dic{
    AddViewController *addVC = [[AddViewController alloc]init];
    addVC.buttonDic = dic;
    addVC.tableId = self.tableId;
    
    [self.navigationController pushViewController:addVC animated:YES];
    
    
}


#pragma mark - createUI
-(void)createUI{
    self.tbView = [[UITableView alloc]init];
    
    [self.view addSubview:self.tbView];
    
    
    self.tbView.delegate = self;
    self.tbView.dataSource = self;
    //    self.tbView.editing = YES;
    self.tbView.separatorStyle =UITableViewCellSeparatorStyleNone;
    if (_titleArr.count >1) {
        [self createTopSelectBtnViewAndBottom:_titleArr.count];
        
        
        
        [self.tbView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.TopSelectbgView.mas_bottom);
            make.left.equalTo(self.view .mas_left);
            make.right.equalTo(self.view.mas_right);
            make.bottom.equalTo(self.view.mas_bottom).offset(-5);
        }];
    }else{
        [self.tbView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top);
            make.left.equalTo(self.view .mas_left);
            make.right.equalTo(self.view.mas_right);
            make.bottom.equalTo(self.view.mas_bottom).offset(-5);
        }];
    }
    

    
    self.tbView.backgroundColor = [UIColor clearColor];
    
    //    self.tbView.frame = CGRectMake(0, 0, 320, 300);
}

#pragma mark - shaixuan click
-(void)searchClick:(UIButton *)btn{
    
    SearchViewController *searchVC = [[SearchViewController alloc]initWithBlock:^(NSDictionary *dic) {
        _searchDic = (NSMutableDictionary *)dic;
    }];
    
    
    
    searchVC.pageID = self.pageId;
    searchVC.tableID = self.tableId;
    searchVC.dataArr = self.searchArr;
    //searchVC.receiveParama = self;
    
    //searchVC.delegate = self;
    
    [self presentViewController:searchVC animated:YES completion:^{
        
        //*** avoid pop come back more request
        self.needRefush = NO;
    }];
    
    
    
}




#pragma 删除请求
-(void)deleRequest:(UIButton *)btn{
    
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userName() forKey:@"loginName"];
    [parmas setObject:passWord() forKey:@"password"];
    [parmas setObject:self.pageId forKey:@"pageId"];
    [parmas setObject:self.tableId forKey:@"tableId"];
    [parmas setObject:@"1" forKey:@"source"];
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    NSString *tableStr = self.tableId;
    NSString *t_str = [NSString stringWithFormat:@"T_%@_0",tableStr];
    for(int i=0;i<_deleArr.count;i++){
        NSDictionary *dic =[_deleArr objectAtIndex:i];
        if([dic objectForKey:t_str]!=nil)[arr addObject:[dic objectForKey:t_str]];
        
    }
    
    NSLog(@"%@", _currentDeleteBtnDic);
    NSString *delIds = [arr componentsJoinedByString:@","];
    [parmas setObject:delIds forKey:@"delIds"];
    [parmas setObject:[_currentDeleteBtnDic objectForKey:@"buttonType"] forKey:@"buttonType"];
    
    [parmas setObject: getSessionId() forKey:@"sessionId"];
    
    NSString *requestStr =[NSString stringWithFormat:@"%@%@", self.programaUrl, DELETE_URL];
    
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        //*** whill deleted or exit dselete shoule remove all object in delete arr
        [self.deleArr removeAllObjects];
        self.tbView.editing = NO;
        [self.tbView reloadData];
        
        self.completeBtn.enabled = YES;
        [self setRightBtn];
        
        if(data!=nil&&!error){
            NSDictionary *obj =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
            if ([obj valueForKey: @"promptMessage"]) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
                
            }
            
            NSString *str=  [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            _alert =[[UIAlertView alloc]initWithTitle:nil message:str delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
            [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
            [_alert show];
            
            
            [_fieldArr removeObjectsInArray:_deleArr];
            [self createBoolArr];
            
            
            begin = 0;
            [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
            
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
        }
        
    }];
    
}

-(void) performDismiss:(NSTimer *)timer
{
    [_alert dismissWithClickedButtonIndex:0 animated:NO];
    
    [timer invalidate];
    
    timer = nil;
}

//-(void)doTime:(NSTimer *)theTimer{
//  UIAlertView *alert = (UIAlertView *)[theTimer userInfo];
//  [alert dismissWithClickedButtonIndex:0 animated:NO];
//alert=NULL;
//[self.tbView reloadData];
//}

#pragma mark - UITableViewCellDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _fieldArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    static NSString *listCell = @"evaCell";
    if (_indexPath == 0||_indexPath == 1) {
        EvaluateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
        if (cell == nil) {
            cell = [[EvaluateTableViewCell alloc]initWithReuseIdentifier:listCell];
            //        cell = [[EvaluateTableViewCell alloc] initWithReuseIdentifier:listCell andIndexPath:indexPath];
            
            
            
        }
        //    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.indexPath = indexPath;
        //    NSLog(@"cell.indexPath.row%ld",(long)indexPath.row);
        //    if (indexPath.row == self.testDataArray.count) {
        //        [self.testDataArray addObject:[NSArray arrayWithObject:@""]];
        //    }
        
        NSLog(@"%@",_testDataArray);
        [cell setMoreEvalutions:[self.testDataArray objectAtIndex:indexPath.row] andforCount:[[self.testDataArray objectAtIndex:indexPath.row] count]];
        //if (CURRENTVERSION>=9.0)
        //{
        //[self registerForPreviewingWithDelegate:self sourceView:cell];
        //  NSLog(@"3D Touch  可用!");
        //}
        //else
        // {
        //  NSLog(@"3D Touch 无效");
        //}
        
        cell.longSelected = self.longSelected;
        //    cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if ([self.boolArr[indexPath.row]isEqualToString:@"NO"]) {
            cell.selectedMore = NO;
            [cell setSelctButton];
        }else if([self.boolArr[indexPath.row]isEqualToString:@"YES"]){
            cell.selectedMore = YES;
            [cell setSelctButton];
        }
        NSMutableArray *arr;
        arr =[NSMutableArray arrayWithArray:_fieldArr];
        NSDictionary *dic = [arr objectAtIndex:indexPath.row];
        
        
        //*** 必须先设置 dic 因为需要先设置一些东西左侧显示 右侧的等等数据 的  操  作
        [cell setDic:dic andCNName:_cnName];
        [cell setSuperViewRect:indexPath];
        
        
        cell.cnName = _cnName;
        
        
        cell.userInteractionEnabled = NO;
        
        
        
        
        cell.mormalBtn.indexPath = indexPath;
        [cell.mormalBtn addTarget:self action:@selector(mroMalbtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        if(_relationAddSelect.count>0){
            cell.mormalBtn.hidden = NO;
            cell.imgLine.hidden = NO;
        }else{
            cell.mormalBtn.hidden = YES;
            cell.imgLine.hidden = YES;
        }
        return cell;

    }else{
        
            static NSString *listCell = @"listCell";
            ListVCCellTwo *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
            if (cell == nil) {
                cell = [[ListVCCellTwo alloc]initWithReuseIdentifier:listCell];
            }
            //    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            NSLog(@"%@",_menuName);
            //        if([[_titleArr firstObject] isEqualToString:@"学员课程教师"]){
            //            cell.Label2R.hidden = YES;
            //
            //        }else{
            //            cell.starV.hidden = YES;
            //        }
        
//                cell.Label2R.hidden = YES;

                cell.starV.hidden = YES;
            cell.indexPath = indexPath;
            
            //if (CURRENTVERSION>=9.0)
            //{
            //[self registerForPreviewingWithDelegate:self sourceView:cell];
            //  NSLog(@"3D Touch  可用!");
            //}
            //else
            // {
            //  NSLog(@"3D Touch 无效");
            //}
            
            
        
            cell.isNeedDownload = NO;
            
            cell.longSelected = self.longSelected;
            //    cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if ([self.boolArr[indexPath.row]isEqualToString:@"NO"]) {
                cell.selectedMore = NO;
                [cell setSelctButton];
            }else if([self.boolArr[indexPath.row]isEqualToString:@"YES"]){
                cell.selectedMore = YES;
                [cell setSelctButton];
            }
            NSMutableArray *arr;
            arr =[NSMutableArray arrayWithArray:_fieldArr];
            NSDictionary *dic = [arr objectAtIndex:indexPath.row];
            
            
            //*** 必须先设置 dic 因为需要先设置一些东西左侧显示 右侧的等等数据 的  操  作
            cell.dic = dic;
            
            
            
            cell.cnName = _cnName;
            
            //        cell.starNUM = 3;
            
            cell.mormalBtn.indexPath = indexPath;
            [cell.mormalBtn addTarget:self action:@selector(mroMalbtnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            if(_relationAddSelect.count>0){
                cell.mormalBtn.hidden = NO;
                cell.imgLine.hidden = NO;
            }else{
                cell.mormalBtn.hidden = YES;
                cell.imgLine.hidden = YES;
            }
            return cell;
            
        
    }
    
    
   
    
}

#pragma mark - 相关项点击事件
-(void)mroMalbtnClick:(NormalButton *)btn{
    
    if(_relationAddSelect.count<=0)return;
    NSDictionary *dic = [_fieldArr objectAtIndex:btn.indexPath.row];
    NSString *str = [NSString stringWithFormat:@"T_%@_0", self.tableId];
    SelectRelationViewController *selcRAVC = [[SelectRelationViewController alloc]init];
    selcRAVC.mainId = [dic valueForKey:str];
    selcRAVC.mainTableId = self.tableId;
    selcRAVC.mainPageId = self.pageId;
    selcRAVC.segmentArr = _relationAddSelect;
    [self.navigationController pushViewController:selcRAVC animated:YES];
}

-(void)longPressClick{
    
    if(!self.canDelete)return;
    if(self.longSelected){
        NSLog(@"a");return;
    }
    self.longSelected = !self.longSelected;
    
    [self setRightBtn];
    
    self.tbView.editing = YES;
    [self.tbView reloadData];
    
}


#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //#ifdef Main
//    if([getUIStyle() isEqualToString:STYLE0]){
//        NSLog(@"主项目程序");
//        
//        if(_relationAddSelect.count>0){
//            return 220 + addHeight + 7 + 36/2;
//        }else{
//            
//            return 220 + addHeight + 20/2;
//        }
//    }else{
    
//        #elif Student
        
        
        if (_indexPath == 0||_indexPath == 1) {
            if (indexPath.row == 0) {
                //            NSInteger i =[_lineNumberArr objectAtIndex:indexPath.row];
                if ([[_lineNumberArr objectAtIndex:indexPath.row] intValue] > 0) {
                    return (224+202+28-40+44)/2+(52+22)/2*[[_lineNumberArr objectAtIndex:indexPath.row] intValue]-54+44/2;
                }else{
                    return (224+202+28-130)/2;
                }
                
            }else{
                if ([[_lineNumberArr objectAtIndex:indexPath.row] intValue] > 0) {
                    //                NSInteger row = indexPath.row;
                    //                NSLog(@"row:%ld",(long)row);
                    //                if (indexPath.row>_lineNumberArr.count-1) {
                    //                    return (224+202+36)/2+(52+22)/2*1-54+44/2;
                    //                }else{
                    //                _testDataArray
                    return (224+202+36-40+44)/2+(52+22)/2*[[_lineNumberArr objectAtIndex:indexPath.row] intValue]-54+44/2;
                    //                }
                    
                }else{
                    return (224+202+36-130)/2;
                }
            }

        }else{
            if(_relationAddSelect.count>0){
                return 220 + addHeight + 7 + 36/2;
            }else{
                return 185 + 58/2;
            }
        }
        
        
//        }
//        EvaluateTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//        
//        return cell.lineNumber*(32+20+22)/2+ 285 + 58/2;
//    }
    //#elif Teacher
    //    //    rootview
    //    NSLog(@"老师端程序");
    //     return 220 + addHeight + 36/2;
    //
    //#else
    //    NSLog(@"都不是");
    //     return 220 + addHeight + 36/2;
    //
    //#endif
    
    
    //*** 默认renturn 确保 不飘红 ， 不为空
    return 220;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    ListVCCell *cell = (ListVCCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.selectedMore = !cell.selectedMore;
    
    if(cell.selectedMore == NO){
        [self.boolArr replaceObjectAtIndex:indexPath.row withObject:@"NO"];
        
        NSString *tableStr = self.tableId;
        NSString *t_str = [NSString stringWithFormat:@"T_%@_0",tableStr];
        
        NSDictionary *currentDic = [_fieldArr objectAtIndex:indexPath.row];
        NSString *str =[NSString stringWithFormat:@"%@", [currentDic objectForKey:t_str]];
        
        for(NSDictionary *dic in _deleArr){
            if([str isEqualToString:[NSString  stringWithFormat:@"%@", [dic objectForKey:t_str]]]){
                NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:_deleArr];
                [arr removeObject:dic];
                _deleArr = arr;
                //                    [_deleArr removeObject:dic];
            }
        }
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//#if Student
//        [tableView deselectRowAtIndexPath:indexPath animated:NO];
//            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    
//#endif
    //
    _isSelectedCell = YES;
    NSLog(@"seleteCellIndex");
    if(self.longSelected){
        ListVCCell *cell = (ListVCCell *)[tableView cellForRowAtIndexPath:indexPath];
        cell.selectedMore = !cell.selectedMore;
        if(cell.selectedMore == YES){
            [self.boolArr replaceObjectAtIndex:indexPath.row withObject:@"YES"];
            NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:_deleArr];
            
            [arr addObject:[_fieldArr objectAtIndex:indexPath.row]];
            _deleArr = arr;
        }else if(cell.selectedMore == NO){
            [self.boolArr replaceObjectAtIndex:indexPath.row withObject:@"NO"];
            for(NSDictionary *dic in _deleArr){
                NSString *str =[NSString stringWithFormat:@"%@", [[_fieldArr objectAtIndex:indexPath.row]objectForKey:@"ROW_ID"]];
                if([str isEqualToString:[NSString  stringWithFormat:@"%@", [dic objectForKey:@"ROW_ID"]]]){
                    NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:_deleArr];
                    [arr removeObject:dic];
                    _deleArr = arr;
                    //                    [_deleArr removeObject:dic];
                }
            }
        }
#warning while real data come open it
        
        NSLog(@"a");return;
    }else{
        if(self.selecCell)return;
        ListDetailViewController *listDVC =[[ListDetailViewController alloc]init];
        
        listDVC.retureView = self;
        listDVC.cnName = _cnName;
        listDVC.buttons = _detailBtns;
        listDVC.tableId = self.tableId;
        listDVC.pageId = self.pageId;
        
        listDVC.dataDic = self.dataDic;
        listDVC.ADDBTN = _ADDBTN;
        self.isPop = @"detail";
        
        
        NSDictionary *dic= [_fieldArr objectAtIndex:indexPath.row];
        listDVC.detailDic = dic;
        self.selecCell = YES;
        [self.navigationController pushViewController:listDVC animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        
    }
}


- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{
    return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
}


-(void)netNotifation:(NSNotification *)noti{
    NSString *reqResStr = [noti object];
    if ([reqResStr isEqualToString:NETSTATE]) {
        self.completeBtn.userInteractionEnabled = YES;
    }else{
        self.completeBtn.userInteractionEnabled = NO;
    }
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (CURRENTVERSION<9.0) {
        if(buttonIndex == 1){
            self.longSelected = !self.longSelected;
            [self deleRequest:self.completeBtn];
        }else if(buttonIndex == 0){
            self.completeBtn.enabled = YES;
        }
    }
    else{
        NSLog(@"%ld",(long)buttonIndex);
    }
}
#pragma mark - TopView

- (void)createTopSelectBtnViewAndBottom:(NSInteger)count{
    if (!_TopSelectbgView) {
        self.TopSelectbgView = [[UIView alloc] init];
        [self.view addSubview:self.TopSelectbgView];
        [_TopSelectbgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top);
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
            make.height.equalTo(@(TopSelectViewHeight));
        }];
    }
    
    self.TopSelectbgView.backgroundColor = [UIColor whiteColor];
    if (count == 2) {
        //----------------------注释位置------------------------------------------
        UIButton *leftBtn = [[UIButton alloc] init];
        UIButton *rightBtn = [[UIButton alloc] init];
        UIView *middleLineView = [[UIView alloc] initWithFrame:CGRectMake(KWIDTH/2, TopSelectBtnMiddelLineTopDistance, 1, 20)];
        middleLineView.backgroundColor = [UIColor colorWithHex:TopSelectBtnMiddelLineColor];
        [self.TopSelectbgView addSubview:middleLineView];
        [self.TopSelectbgView addSubview:leftBtn];
        [self.TopSelectbgView addSubview:rightBtn];
        leftBtn.frame = CGRectMake(0, 0, KWIDTH/2, TopSelectBtnHeight);
        leftBtn.center = CGPointMake(KWIDTH/4, 40/2);
        rightBtn.frame = CGRectMake(KWIDTH/2, 0, KWIDTH/2, TopSelectBtnHeight);
        rightBtn.center = CGPointMake(KWIDTH/4*3, 40/2);
        leftBtn.tag = TopSelectBtnTagBegain;
        rightBtn.tag = TopSelectBtnTagBegain+1;
        [leftBtn addTarget:self action:@selector(TopSelectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [rightBtn addTarget:self action:@selector(TopSelectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [leftBtn setTitle:[_titleArr firstObject] forState:UIControlStateNormal];
        [rightBtn setTitle:[_titleArr lastObject] forState:UIControlStateNormal];
        [leftBtn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateNormal];
        [rightBtn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColorNormal] forState:UIControlStateNormal];
        [rightBtn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateHighlighted];
        
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:TopSelectBtnTextFont];
        leftBtn.titleLabel.font = [UIFont systemFontOfSize:TopSelectBtnTextFont];
        
        rightBtn.titleLabel.lineBreakMode =  NSLineBreakByTruncatingTail;
        leftBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        CGSize rect = [self calculateOneTextLenth:[_titleArr firstObject] andTitleFont:TopSelectBtnTextFont];
        if (!_BtnLineView) {
            _BtnLineView = [[UIView alloc] init];
            [self.TopSelectbgView addSubview:_BtnLineView];
            _BtnLineView.backgroundColor = [UIColor colorWithHex:TopSelectBtnBottomLineColor];
            [_BtnLineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.TopSelectbgView).offset(-TopSelectBtnBottomLineBottomDistance);
                make.centerX.equalTo(leftBtn.mas_centerX);
                make.width.equalTo(@(rect.width));
                make.height.equalTo(@(TopSelectBtnBottomLineHeight));
            }];
        }
        //------------------------以上是2个标题的情况----------------------------
        
        //
        
        //----------测试用--------------
        //        NSMutableArray *array = [NSMutableArray arrayWithArray:_titleArr];
        //        for (int i = 0; i < 10; i++) {
        //            [array addObject:[NSString stringWithFormat:@"第%d个",i]];
        //        }
        //----------测试用结束-----------
        
        
        
        
        UIView *lineView = [[UIView alloc] init];
        [self.TopSelectbgView addSubview:lineView];
        lineView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(1));
            make.left.equalTo(self.TopSelectbgView.mas_left);
            make.right.equalTo(self.TopSelectbgView.mas_right);
            make.bottom.equalTo(self.TopSelectbgView.mas_bottom);
        }];
        
        
        
        
    }else{
        CGRect rect = [self calculateTextLenth:_titleArr andTitleFont:TopSelectBtnTextFont];
        NSLog(@"%@",NSStringFromCGRect(rect));
        
        NSInteger RealLenth = rect.size.width +20;
        _realLength = RealLenth;
        _sv = [[UIScrollView alloc] init];
        _sv.userInteractionEnabled = YES;
        _sv.delegate = self;
        _sv.scrollEnabled = YES;
        [self.TopSelectbgView addSubview:_sv];
        [_sv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.TopSelectbgView);
        }];
        //        sv.backgroundColor = [UIColor yellowColor];
        UIImageView *bigView = [[UIImageView alloc] initWithImage:nil];
        [_sv addSubview:bigView];
        [bigView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sv.mas_top);
            make.left.equalTo(_sv.mas_left);
            make.width.equalTo(@(RealLenth));
            make.height.equalTo(@(40));
        }];
        [_sv setShowsHorizontalScrollIndicator:NO];
        bigView.userInteractionEnabled = YES;
        //        bigView.backgroundColor = [UIColor purpleColor];
        _sv.contentSize = CGSizeMake(RealLenth, 40);
        
        for (int i = 0; i < _titleArr.count; i++) {
            UIButton *btn = [[UIButton alloc] init];
            [bigView addSubview:btn];
            btn.tag = TopSelectBtnTagBegain + i;
            //            btn.text = [array objectAtIndex:i];
            //            btn.textColor = [UIColor colorWithHex:TopSelectBtnTextColor];
            //            btn.userInteractionEnabled = NO;
            //            btn.font = [UIFont systemFontOfSize:TopSelectBtnTextFont];
            
            CGRect rects = [[_titleArr objectAtIndex:i] boundingRectWithSize:CGSizeMake(KWIDTH, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TopSelectBtnTextFont]} context:nil];
            btn.titleLabel.font = [UIFont systemFontOfSize:TopSelectBtnTextFont];
            if (i == 0) {
                [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateNormal];
                if (!_BtnLineView) {
                    _BtnLineView = [[UIView alloc] init];
                    [bigView addSubview:_BtnLineView];
                    _BtnLineView.backgroundColor = [UIColor colorWithHex:TopSelectBtnBottomLineColor];
                    [_BtnLineView mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.bottom.equalTo(self.TopSelectbgView).offset(-TopSelectBtnBottomLineBottomDistance);
                        make.centerX.equalTo(btn.mas_centerX);
                        CGSize rect = [self calculateOneTextLenth:[_titleArr objectAtIndex:i] andTitleFont:TopSelectBtnTextFont];
                        make.width.equalTo(@(rect.width));
                        make.height.equalTo(@(TopSelectBtnBottomLineHeight));
                    }];
                }
                
            }else{
                [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColorNormal] forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateHighlighted];
                UIView *middleLineView = [[UIView alloc] init];
                middleLineView.backgroundColor = [UIColor colorWithHex:TopSelectBtnMiddelLineColor];
                [bigView addSubview:middleLineView];
                [middleLineView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(bigView.mas_top).offset(TopSelectBtnMiddelLineTopDistance);
                    make.right.equalTo(btn.mas_left).offset(-10);
                    make.width.equalTo(@(1));
                    make.bottom.equalTo(bigView.mas_bottom).offset(-TopSelectBtnMiddelLineBottomDistance);
                    
                }];
            }
            
            [btn addTarget:self action:@selector(TopSelectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [btn setTitle:[_titleArr objectAtIndex:i] forState:UIControlStateNormal];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(bigView.mas_centerY);
                if (i != 0) {
                    UIButton *beforeBtn = [_sv viewWithTag:TopSelectBtnTagBegain+i-1];
                    make.left.equalTo(beforeBtn.mas_right).offset(20);
                    
                }
                else{
                    make.left.equalTo(bigView.mas_left).offset(20);
                }
                //                make.width.equalTo(@(rects.size.width));
                make.height.equalTo(@(TopSelectBtnHeight));
            }];
            
            
            
            
            
        }
        UIView *lineView = [[UIView alloc] init];
        [_sv addSubview:lineView];
        lineView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(1));
            make.left.equalTo(_sv.mas_left);
            make.right.equalTo(_sv.mas_right);
            make.bottom.equalTo(_sv.mas_bottom);
        }];
    }
    
    
    
    
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"滚");
}

- (void)TopSelectBtnClick:(UIButton *)sender{
    if(self.requeatResultLabel)[self.requeatResultLabel removeFromSuperview];
    NSLog(@"%@，%@",self.pageId,self.tableId);
    _indexPath = sender.tag-TopSelectBtnTagBegain;
    NSLog(@"indexPath = %ld",(long)_indexPath);
    //    NSMutableArray *array = [NSMutableArray arrayWithArray:_titleArr];
    //    for (int i = 0; i < 10; i++) {
    //        [array addObject:[NSString stringWithFormat:@"第%d个",i]];
    //    }
    for (int i = 0; i<_titleArr.count; i++) {
        UIButton *btn = [self.TopSelectbgView viewWithTag:TopSelectBtnTagBegain+i];
        if (btn == sender) {
            NSLog(@"点中");
            [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateHighlighted];
            btn.userInteractionEnabled = NO;
        }else{
            [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColorNormal] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHex:TopSelectBtnTextColor] forState:UIControlStateHighlighted];
            btn.userInteractionEnabled = YES;
        }
    }
    [UIView animateWithDuration:0.5 animations:^{
        CGSize rect = [self calculateOneTextLenth:[_titleArr objectAtIndex:sender.tag - TopSelectBtnTagBegain] andTitleFont:TopSelectBtnTextFont];
        CGRect frame = _BtnLineView.frame;
        frame.size.width = rect.width;
        _BtnLineView.frame = frame;
        //    _BtnLineView.center.x = KWIDTH/4*3;
        CGPoint center = _BtnLineView.center;
        center.x = sender.center.x;
        _BtnLineView.center = center;
    }];
    NSDictionary *selectDic = [_secondArr objectAtIndex:(sender.tag-TopSelectBtnTagBegain)];
    NSString *pageId = [selectDic objectForKey:@"pageId"];
    NSString *tableId = [selectDic objectForKey:@"tableId"];
    NSLog(@"%@, %@",pageId,tableId);
    self.pageId = pageId;
    self.tableId = tableId;
    [self dataRequestWithBegining:begin andLimit:limit andIsFooter:NO];
    if (_transformFlag == 0) {
        //                [UIView animateWithDuration:0.3
        //                                 animations:^{
        //                                     _mytransformIV.transform = CGAffineTransformRotate(_mytransformIV.transform, M_PI);
        //                                 }];
        _transformFlag = 1;
    }
    
    
    
    
    
}


//- (CGRect)calculateTextLenth:(NSArray *)titleArray{
//    //    allLenth = [NSString stringWithFormat:@"%@%@",allLenth,[[self.testDataArray objectAtIndex:j] objectAtIndex:i]];
//    NSString *allLenth = [[NSString alloc] init];
//    for (int i = 0; i < titleArray.count; i++) {
//        allLenth = [NSString stringWithFormat:@"%@%@",allLenth,[titleArray objectAtIndex:i]];
//    }
//    
//    
//    UILabel *la =[[UILabel alloc]init];
//    la.text = allLenth;
//    float hh = [la sizeThatFits:CGSizeMake(CGFLOAT_MAX, 40)].width;//动态计算高度
//    hh += titleArray.count*10+5;
//    CGRect rect = [allLenth boundingRectWithSize:CGSizeMake(KWIDTH, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TopSelectBtnTextFont]} context:nil];
//    for (NSString*title in titleArray) {
//        rect.size.width += title.length * 4.5+20;
//    }
//    NSLog(@"%zd",rect.size.width);
//    //    NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
//    //    CGFloat lineBeyond = ceil(lenth/(KWIDTH-45));
//    rect.size.width = hh;
//    return rect;
//}
//
//- (CGSize)calculateOneTextLenth:(NSString *)title{
//    
//    UILabel *la =[[UILabel alloc]init];
//    la.text = title;
//    float hh = [la sizeThatFits:CGSizeMake(CGFLOAT_MAX, 40)].width;//动态计算高度
//    CGSize rect = [title boundingRectWithSize:CGSizeMake(KWIDTH, 30) options:NSStringDrawingTruncatesLastVisibleLine |
//                   
//                   NSStringDrawingUsesLineFragmentOrigin |
//                   
//                   NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TopSelectBtnTextFont]} context:nil].size;
//    //    rect.width += title.length * 2-2;
//    rect.width = hh;
//    //    NSInteger lenth = rect.size.width + (k+1)*(14+22)/2+50/2;
//    //    CGFloat lineBeyond = ceil(lenth/(KWIDTH-45));
//    return rect;
//}
-(void)viewDidLayoutSubviews
{
    _sv.contentSize = CGSizeMake(_realLength,40);
    _sv.bounces = NO;
}
#pragma mark - TopViewEnd

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:SHOULDRELOAD object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"row" object:nil];
    
    NSLog(@"-------------- 释放 ----------");
}
#pragma mark - 重写showLabel方法
-(void)showLabelWithText:(NSString *)text{
    if (getLeftRightModel()&&_titleArr.count>1) {
        if(self.requeatResultLabel!=nil)return;
        self.requeatResultLabel = [[UILabel alloc]init];
        self.requeatResultLabel.backgroundColor = [UIColor colorWithRed:30/255.0 green:25/255.0 blue:77/255.0 alpha:0.4];
        self.requeatResultLabel.textColor = [UIColor whiteColor];
        self.requeatResultLabel.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:self.requeatResultLabel];
        if(CURRENTVERSION<9.0){
            self.requeatResultLabel.frame = CGRectMake(0, -25, self.view.bounds.size.width, 25);
            CGRect frame = self.requeatResultLabel.frame;
            self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
            self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
            [self.view bringSubviewToFront:self.requeatResultLabel];
            [UIView animateWithDuration:1 animations:^{
                self.requeatResultLabel.frame = CGRectMake(0, 40, self.view.bounds.size.width, 25);
                
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:1 animations:^{
                    self.requeatResultLabel.frame = frame;
                } completion:^(BOOL finished) {
                    [self.requeatResultLabel removeFromSuperview];
                    self.requeatResultLabel = nil;
                }];
            }];
        }else{
            self.requeatResultLabel.frame = CGRectMake(0, 40, self.view.bounds.size.width, 0);
            CGRect frame = self.requeatResultLabel.frame;
            self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
            self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
            [self.view bringSubviewToFront:self.requeatResultLabel];
            [UIView animateWithDuration:1 animations:^{
                self.requeatResultLabel.frame = CGRectMake(0, 40, self.view.bounds.size.width, 25);
                
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:1 animations:^{
                    self.requeatResultLabel.frame = frame;
                } completion:^(BOOL finished) {
                    [self.requeatResultLabel removeFromSuperview];
                    self.requeatResultLabel = nil;
                }];
            }];
            
        }
    }else{
        if(self.requeatResultLabel!=nil)return;
        self.requeatResultLabel = [[UILabel alloc]init];
        self.requeatResultLabel.backgroundColor = [UIColor colorWithRed:30/255.0 green:25/255.0 blue:77/255.0 alpha:0.4];
        self.requeatResultLabel.textColor = [UIColor whiteColor];
        self.requeatResultLabel.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:self.requeatResultLabel];
        if(CURRENTVERSION<9.0){
            self.requeatResultLabel.frame = CGRectMake(0, -25, self.view.bounds.size.width, 25);
            CGRect frame = self.requeatResultLabel.frame;
            self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
            self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
            [self.view bringSubviewToFront:self.requeatResultLabel];
            [UIView animateWithDuration:1 animations:^{
                self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 25);
                
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:1 animations:^{
                    self.requeatResultLabel.frame = frame;
                } completion:^(BOOL finished) {
                    [self.requeatResultLabel removeFromSuperview];
                    self.requeatResultLabel = nil;
                }];
            }];
        }else{
            self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 0);
            CGRect frame = self.requeatResultLabel.frame;
            self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
            self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
            [self.view bringSubviewToFront:self.requeatResultLabel];
            [UIView animateWithDuration:1 animations:^{
                self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 25);
                
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:1 animations:^{
                    self.requeatResultLabel.frame = frame;
                } completion:^(BOOL finished) {
                    [self.requeatResultLabel removeFromSuperview];
                    self.requeatResultLabel = nil;
                }];
            }];
            
        }
    }
}

@end
